package com.sx.pipeline.ui.needs.construction.approve

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.android.material.tabs.TabLayoutMediator
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActReleaseTaskListBinding


/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 我审批的需求
 */
@Route(path = RoutePath.Mine.APPROVE_NEEDS)
class ApprovalNeedsActivity :
    CYDataBindingBaseActivity<ActReleaseTaskListBinding, ApprovalNeedsVM>(
        R.layout.act_release_task_list
    ), View.OnClickListener {
    private lateinit var releasePageAdapter: ApprovalNeedsPageAdapter


    override fun initData() {
        mBinding.setVariable(BR.onClick, this)
        mBinding.titleBar.title = getString(R.string.txt_my_approval_needs)
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
        initPager()
    }

    /**
     * 初始化ViewPager
     */
    private fun initPager() {
        if (mBinding.viewPager.adapter == null) {
            releasePageAdapter = ApprovalNeedsPageAdapter(
                mViewModel.getApprovalRequireTabsList(), supportFragmentManager, lifecycle
            )
        }
        mBinding.viewPager.adapter = releasePageAdapter
        mBinding.viewPager.offscreenPageLimit=mViewModel.getApprovalRequireTabsList().size

        //绑定tabLayout和viewPager
        TabLayoutMediator(
            mBinding.tab, mBinding.viewPager,
            true, true
        ) { tab, position ->
            tab.text = mViewModel.getApprovalRequireTabsList()[position]
        }.attach()
    }

    override fun onClick(v: View?) {
        when (v?.id) {

        }
    }

}